package views;
import controller.UserController;
import controller.MemberController;
import entity.User;
import entity.Member;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class MemberView {
    MemberController memberController=new MemberController();
    UserController userController=new UserController();
    BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
    /*
    会员添加界面
     */
    public boolean insertMemberView(){
        try{
            System.out.println("————————欢迎进入会员办理界面————————");
            System.out.println("请输入您想要办理会员的用户的id");
            String id=bufferedReader.readLine();
            System.out.println("请输入密保答案");
            String answer=bufferedReader.readLine();
            User user=userController.seekUserById(Integer.parseInt(id));
            if(user.getAnswer().equals(answer)){
                System.out.println("请输入想要办理的QQ会员名称");
                String QQmember=bufferedReader.readLine();
                System.out.println("请输入想要办理的视频会员的名称");
                String Videomember=bufferedReader.readLine();
                System.out.println("请输入想要办理的音乐会员的名称");
                String Musicmember=bufferedReader.readLine();
                System.out.println("请输入想要办理的看点会员的名称");
                String Lookmember=bufferedReader.readLine();
                Member member1=new Member(Integer.parseInt(id),QQmember,Videomember,Musicmember,Lookmember);
                System.out.println(member1);
                return memberController.insertMemberController(member1);
            }
        }
        catch (IOException e){
            System.out.println("io异常,办理失败!");
            return false;
        }
        return false;
    }
    /*
    根据视频会员,进入会员删除界面,进行会员删除
     */
    public boolean deleteMemberView(){
        try{
            System.out.println("————————欢迎进入会员删除界面————————");
            System.out.println("请输入你想要删除的会员的用户id");
            String id=bufferedReader.readLine();
            System.out.println("请输入你想要删除的会员的视频会员");
            String Videomember=bufferedReader.readLine();
            System.out.println("请输入密保答案");
            String answer=bufferedReader.readLine();
            User user=userController.seekUserById(Integer.parseInt(id));
            if(user.getAnswer().equals(answer)){
                return memberController.deleteMemberByVideomemberController(Integer.parseInt(id),Videomember);
            }
        }
        catch (IOException e){
            System.out.println("io异常,删除失败!");
            return false;
        }
        return false;
    }
    /*
    根据视频会员,更改用户会员信息
     */
    public boolean changeMemberView(){
        try{
            System.out.println("————————欢迎进入用户会员权益更改页面————————");
            System.out.println("请输入您想要更改会员权益的用户的id");
            String id=bufferedReader.readLine();
            System.out.println("请输入想要更改的用户的会员权益的视频会员权益");
            String Videomember=bufferedReader.readLine();
            System.out.println("请输入密保答案");
            String answer=bufferedReader.readLine();
            System.out.println("请输入想要更改的会员权益的主会员权益");
            String QQmember=bufferedReader.readLine();
            System.out.println("请输入想要更改的会员权益的视频会员权益");
            String Videomember1=bufferedReader.readLine();
            System.out.println("请输入想要更改的会员权益的音乐会员权益");
            String Musicmember=bufferedReader.readLine();
            System.out.println("请输入想要更改的会员权益的看点会员权益");
            String Lookmember=bufferedReader.readLine();
            Member member=new Member(Integer.parseInt(id),QQmember,Videomember1,Musicmember,Lookmember);
            User user=userController.seekUserById(Integer.parseInt(id));
            if(user.getAnswer().equals(answer)){
                return memberController.changeMemberByIdService(Integer.parseInt(id),Videomember,member);
            }
        }
        catch (IOException e){
            System.out.println("io异常,更改会员权益失败!");
            return false;
        }
        return false;
    }
    /*
    用户会员权益查询(查询所有用户,根据id查询单个指定用户)
     */
    public void seekMemberView(){
        try{
            System.out.println("————————欢迎进入会员权益查询界面————————");
            System.out.println("请选择你要执行的查询方式:");
            System.out.println("1、查询所有用户会员权益，2、根据id查询指定单个用户会员权益");
            switch(Integer.parseInt(bufferedReader.readLine())) {
                case 1:
                    System.out.println("请输入您的id");
                    String id1 = bufferedReader.readLine();
                    User user = userController.seekUserById(Integer.parseInt(id1));
                    if ( user.getCall() == 2) {
                        System.out.println(memberController.seekAllMemberService());
                    }
                    else {
                        System.out.println("很抱歉,您没有访问的权限!");
                    }
                    break;
                case 2:
                    System.out.println("请输入您想要查询会员权益的用户id");
                    String id=bufferedReader.readLine();
                    System.out.println("请输入密保答案");
                    String answer=bufferedReader.readLine();
                    User user1=userController.seekUserById(Integer.parseInt(id));
                    if(user1.getAnswer().equals(answer)){
                        System.out.println(memberController.seekMemberByIdController(Integer.parseInt(id)));
                    }
                    else {
                        System.out.println("密保答案错误,查询失败!");
                    }
                    break;
                default:
                    System.out.println("输入内容系统无法识别!");
                    break;
            }
        }
        catch (IOException e){
            System.out.println("io异常,查询失败!");
        }
    }
}
